package com.jpush;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

import java.io.IOException;

public class AsmClient {
    public static void main(String[] args) throws IOException {
        // 拦截Runnable 方法，这是个很简单asm的应用
        ClassPrinter printer = new ClassPrinter();
        ClassReader cr = new ClassReader("java.lang.Runnable");
        cr.accept(printer,0);


    }


    static class ClassPrinter extends ClassVisitor{

        public ClassPrinter() {
            super(Opcodes.ASM7);
        }

        @Override
        public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
            super.visit(version, access, name, signature, superName, interfaces);
            System.out.println("--supername:"+superName+",name:"+name);
        }

        @Override
        public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
            System.out.println(name+descriptor);
            return super.visitMethod(access, name, descriptor, signature, exceptions);
        }

        @Override
        public void visitEnd() {
            System.out.println("visit end..");
            super.visitEnd();
        }
    }
}
